<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>统计考试科目成绩</title>
	</head>
	<body>
		<input name="score" type="button"  value="统计考试科目成绩：" onclick="count(prompt('请输入总科目数量',''))"/>
		<script type="text/javascript" charset="UTF-8">
		
			function count(num) {
				var sum = 0;
				if(!isNaN(num)){
					for (var i = num; i > 0 ; i--){
						var s =  prompt(("请输入单科目成绩："),"");
						if(isNaN(s)) {
							alert("输入的成绩不是数字");
						}else if(s < 0){
							alert("成绩不能是负数！！！");
						} else {
							s = parseFloat(s);
							 sum = (sum + s);
						}
					}
					alert("总成绩是："+ sum);
				} else {
					alert("输入的不是数字");
				}
			}
		</script>
	</body>
</html>
